package unq.tpi.persistencia.performanceEj.servicios;

import java.util.List;

import unq.tpi.persistencia.performanceEj.daos.DepartmentDAO;
import unq.tpi.persistencia.performanceEj.model.Department;
import unq.tpi.persistencia.performanceEj.model.Employee;
import unq.tpi.persistencia.performanceEj.model.EmployeeResume;

public class ListadoPagosPorDepto extends AbstractListado {

	private String num;
	private Department depto = null;

	public ListadoPagosPorDepto(String num) {
		this.num = num;
	}

	@Override
	protected void doListado() throws Exception {
		//depto = new DepartmentDAO().getByCode(num);
         List<EmployeeResume> empleados = new DepartmentDAO().getEmployeeResumeByCode(num);
         System.out.println(empleados.get(0));
		this.newLine();
		this.addColumn("Total").addColumn(this.getTotalSalariesFromResume(empleados)).newLine();
		this.newLine();
		
		this.addColumn("Nombre");
		this.addColumn("Titulo");
		this.addColumn("Monto");
		this.newLine();

		for (EmployeeResume e : empleados) {
			this.addColumn(e.getFullName());
			this.addColumn(e.getTitle());
			this.addColumn(e.getSalaryAmount());
			this.newLine();
		}
	}
	
	public Double getTotalSalariesFromResume(List<EmployeeResume> employees) {
		Double tot = 0D;

		for (EmployeeResume e : employees) {
			tot += e.getSalaryAmount();
		}

		return tot;
	}

	@Override
	public String getFilename() {
		return "./target/PagosPorDepto.csv";
	}
}
